Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@cucumber/gherkin
Advanced tools
@cucumber/gherkin is an npm package that provides tools for parsing Gherkin language, which is used for writing structured tests in a human-readable format. It is part of the Cucumber suite of tools for Behavior-Driven Development (BDD). The package allows you to parse Gherkin documents, extract feature files, and convert them into a format that can be used for automated testing.
Parsing Gherkin Documents
This feature allows you to parse Gherkin documents from a stream. The code sample demonstrates how to create a readable stream from a Gherkin source string and parse it using GherkinStreams. The parsed data is then logged to the console.
const { GherkinStreams } = require('@cucumber/gherkin');
const { Readable } = require('stream');
const gherkinSource = `
Feature: Example feature
Scenario: Example scenario
Given a step
When another step
Then a final step
`;
const stream = Readable.from([gherkinSource]);
const parser = GherkinStreams.fromStream(stream);
parser.on('data', (envelope) => {
console.log(JSON.stringify(envelope, null, 2));
});
Extracting Feature Files
This feature allows you to extract and parse feature files from the file system. The code sample demonstrates how to create a readable stream from a feature file and parse it using GherkinStreams. The parsed data is then logged to the console.
const { GherkinStreams } = require('@cucumber/gherkin');
const fs = require('fs');
const filePath = 'path/to/your/feature/file.feature';
const stream = fs.createReadStream(filePath);
const parser = GherkinStreams.fromStream(stream);
parser.on('data', (envelope) => {
console.log(JSON.stringify(envelope, null, 2));
});
Converting Gherkin to JSON
This feature allows you to convert Gherkin documents into JSON format. The code sample demonstrates how to create a readable stream from a Gherkin source string, parse it using GherkinStreams, and log the Gherkin document in JSON format to the console.
const { GherkinStreams } = require('@cucumber/gherkin');
const { Readable } = require('stream');
const gherkinSource = `
Feature: Example feature
Scenario: Example scenario
Given a step
When another step
Then a final step
`;
const stream = Readable.from([gherkinSource]);
const parser = GherkinStreams.fromStream(stream);
parser.on('data', (envelope) => {
if (envelope.gherkinDocument) {
console.log(JSON.stringify(envelope.gherkinDocument, null, 2));
}
});
The 'cucumber' package is a comprehensive tool for running BDD tests written in Gherkin. It includes a test runner, step definitions, and reporting tools. While @cucumber/gherkin focuses on parsing Gherkin documents, 'cucumber' provides a full suite of tools for executing and managing BDD tests.
The 'jest-cucumber' package integrates Gherkin-based BDD testing with the Jest testing framework. It allows you to write feature files in Gherkin and implement step definitions using Jest. Compared to @cucumber/gherkin, 'jest-cucumber' is more focused on integrating with Jest for test execution.
The 'cypress-cucumber-preprocessor' package enables the use of Gherkin syntax in Cypress tests. It preprocesses feature files and allows you to write step definitions in JavaScript. This package is useful for those who want to combine the power of Cypress for end-to-end testing with Gherkin syntax for BDD.
Gherkin parser/compiler for JavaScript. Please see Gherkin for details.
Typical usage is via the gherkin-streams
package.
[24.1.0] - 2022-10-10
FAQs
Gherkin parser
The npm package @cucumber/gherkin receives a total of 1,012,602 weekly downloads. As such, @cucumber/gherkin popularity was classified as popular.
We found that @cucumber/gherkin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.